package main

// @author liyang<654516092@qq.com>
// @date  2020/5/8 11:31
import (
	"context"
	"strconv"

	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/comtreeData"
	"git.900sui.cn/kc/rpcinterface/client/elastic/staff"
	comtreeData2 "git.900sui.cn/kc/rpcinterface/interface/comtreeData"
	"github.com/streadway/amqp"
)

func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.setStaffToEs"), func(msg amqp.Delivery) {
		staffId, err := strconv.Atoi(string(msg.Body))
		if err != nil {
			return
		}
		rpcEsStaff := new(staff.Staff).Init()
		defer rpcEsStaff.Close()
		reply := false
		if err := rpcEsStaff.SetStaff(context.Background(), &staffId, &reply); err != nil {
			return
		}
		//商户从业人员-MerchantEmployee
		rpcMerchantEmployee := new(comtreeData.MerchantEmployee).Init()
		defer rpcMerchantEmployee.Close()
		args := &comtreeData2.ArgsMerchantEmployee{
			EId: staffId,
		}
		var replys bool
		if err := rpcMerchantEmployee.AddMerchantEmployeeRpc(context.Background(), args, &replys); err != nil {
			return
		}
		return
	})
	if err != nil {
		panic(err)
	}
}
